﻿<%@ Page Title="teaminfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnxc.Web.teaminfo.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Script/upimg.js"></script>
    <script src="../Script/username.js"></script>
     <script type="text/javascript">
         $(function () {
             InitGird();
             InitSearch();
         });
         Date.prototype.pattern = function (fmt) {
             var o = {
                 "M+": this.getMonth() + 1, //月份        
                 "d+": this.getDate(), //日        
                 "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时        
                 "H+": this.getHours(), //小时        
                 "m+": this.getMinutes(), //分        
                 "s+": this.getSeconds(), //秒        
                 "q+": Math.floor((this.getMonth() + 3) / 3), //季度        
                 "S": this.getMilliseconds() //毫秒        
             };
             var week = {
                 "0": "/u65e5",
                 "1": "/u4e00",
                 "2": "/u4e8c",
                 "3": "/u4e09",
                 "4": "/u56db",
                 "5": "/u4e94",
                 "6": "/u516d"
             };
             if (/(y+)/.test(fmt)) {
                 fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
             }
             if (/(E+)/.test(fmt)) {
                 fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
             }
             for (var k in o) {
                 if (new RegExp("(" + k + ")").test(fmt)) {
                     fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                 }
             }
             return fmt;
         }
         var Common = {

             //EasyUI用DataGrid用日期格式化
             TimeFormatter: function (value, rec, index) {
                 if (value == undefined) {
                     return "";
                 }
                 /*json格式时间转js时间格式*/
                 value = value.substr(1, value.length - 2);
                 var obj = eval('(' + "{Date: new " + value + "}" + ')');
                 var dateValue = obj["Date"];
                 if (dateValue.getFullYear() < 1900) {
                     return "";
                 }
                 var val = dateValue.pattern("yyyy-MM-dd HH:mm");
                 return val;
             },
             DateTimeFormatter: function (value, rec, index) {

                 if (value == null || value == '') {
                     return '';
                 }
                 var dt;
                 if (value instanceof Date) {
                     dt = value;
                 }
                 else {
                     dt = new Date(value);
                     if (isNaN(dt)) {
                         value = value.replace(/\/Date\((-?\d+)\)\//, '$1'); //标红的这段是关键代码，将那个长字符串的日期值转换成正常的JS日期格式
                         dt = new Date();
                         dt.setTime(value);
                     }
                 }
                 return dt.pattern("yyyy年M月d日");
             },

             //EasyUI用DataGrid用日期格式化
             DateFormatter: function (value, rec, index) {
                 if (value == undefined) {
                     return "";
                 }
                 /*json格式时间转js时间格式*/
                 value = value.substr(1, value.length - 2);
                 var obj = eval('(' + "{Date: new " + value + "}" + ')');
                 var dateValue = obj["Date"];
                 if (dateValue.getFullYear() < 1900) {
                     return "";
                 }

                 return dateValue.pattern("yyyy-MM-dd");
             }
         };
         function ww4(date) {
             var y = date.getFullYear();
             var m = date.getMonth() + 1;
             var d = date.getDate();
             var h = date.getHours();
             return y + '年' + (m < 10 ? ('0' + m) : m) + '月' + (d < 10 ? ('0' + d) : d) + '日' + (h < 10 ? ('0' + h) : h) + '点';

         }
         function w4(s) {
             return new Date(Date.parse(s.replace(/-/g, "/")));            
         }
         //初始化表格
         function InitGird() {
             $('#tt').datagrid({
                 title: '防治队伍列表', //表格标题
                 url: 'GetTeam.ashx', //请求数据的页面
                 sortName: 'tbh', //排序字段
                 idField: 'tid', //标识字段,主键
                 iconCls: '', //标题左边的图标
                 width: '100%', //宽度
                 //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                 nowrap: false, //是否换行，True 就会把数据显示在一行里
                 striped: true, //True 奇偶行使用不同背景色
                 collapsible: false, //可折叠
                 sortOrder: 'desc', //排序类型
                 remoteSort: true, //定义是否从服务器给数据排序
                 fitColumns: true,
                 method: 'post',
                 columns: [[
                     { field: 'ckb', checkbox: true },                     
                     { title: '编号', field: 'tbh', width: 80, sortable: true },
                     { title: '姓名', field: 'tname', width: 80 },
                     { title: '性别', field: 'tsex', width: 40 },
                     { title: '身份证号', field: 'tno', width: 180 },
                     { title: '手机', field: 'tphone', width: 100 },
                     { title: '邮箱', field: 'temail', width: 150 },
                     { title: '职务', field: 'tpost', width: 100 },
                     { title: '负责区域', field: 'tarea', width: 150 },
                     { title: '职称', field: 'tjob', width: 100 },                     
                     { title: '学历', field: 'tedu', width: 80 },
                     {
                         title: '入职时间', field: 'ttime', width: 150, formatter: function (value, row, index) {
                             if (value != "") {                                
                                 if (value.indexOf("-") != -1)
                                     value = value.replace(/-/g, "/")
                                 return new Date(value).pattern("yyyy年M月d日");
                             }
                             //return value;
                         }
                         
                     },
                     { title: '荣誉', field: 'thonour', width: 150 },
                     { title: '照片', field: 'tpic', width: 150, formatter: function (value, row, index) { return '<img height=32 width=32 src="' + row.tpic + '" />'; } }
                 ]],
                 toolbar: "#tab_toolbar",
                 queryParams: { "action": "query" },
                 pagination: true, //是否开启分页
                 pageNumber: 1, //默认索引页
                 pageSize: 20, //默认一页数据条数
                 rownumbers: true //行号
             });


         }
         //初始化搜索框
         function InitSearch() {
             $("#ipt_search").searchbox({
                 width: 200,
                 //iconCls: 'icon-save',
                 searcher: function (val, name) {
                     $('#tt').datagrid('options').queryParams.search_type = name;
                     $('#tt').datagrid('options').queryParams.search_value = val;
                     $('#tt').datagrid('reload');
                 },
                 prompt: '请输入查询信息'
             });
         }        
         function newUser() {
             //清空内容  
             $('#aspnetForm').form('clear');

             $('#dlg').dialog('open').dialog('setTitle', '添加人员');
             document.getElementById("test").value = "add";
         }

         function editUser() {

             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要修改的行！", "info");
             }
             if (row) {
                 $('#dlg').dialog('open').dialog('setTitle', '修改人员');
                 $('#tid').val(row.tid);
                 $('#htpic').val(row.tpic);
                 document.getElementById("test").value = "modify";
                 $('#aspnetForm').form('load', row);
                // $('#ttime').datebox("setValue", new Date(row.ttime).pattern("yyyy-MM-dd"));
             }
         }
         //添加        
         function saveUser() {
             var test = document.getElementById("test").value;
             var f = $('#aspnetForm');
             if (test == "add") {                
                 f.form('submit', {
                     url: "GetTeam.ashx?action=" + test,
                     onSubmit: function () {
                         return $(this).form('validate');
                     },
                     success: function (result) {
                         if (result.indexOf("T") == 0) {
                             $('#dlg').dialog('close');
                             $.messager.alert("提示", "恭喜您，人员信息添加成功", "info");
                             $('#tt').datagrid('reload');
                         }
                         else if ((result.indexOf("F") == 0)) {
                             $.messager.alert("提示", "添加失败，请重新操作！", "info");
                             return;
                         }
                         else if ((result.indexOf("P") == 0)) {
                             $.messager.alert("提示", "图片格式不对！", "info");
                             return;
                         }
                         else if ((result.indexOf("L") == 0)) {
                             $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                             top.location = '/index.aspx';
                             return;
                         }
                     }
                 });

             } else {

                 $('#aspnetForm').form('submit', {
                     url: "GetTeam.ashx?action=" + test,
                     onSubmit: function () {
                         return $(this).form('validate');
                     },
                     success: function (result) {
                         if (result.indexOf("T") == 0) {
                             $('#dlg').dialog('close');
                             $('#tt').datagrid('clearSelections');
                             $.messager.alert("提示", "恭喜您，人员信息修改成功", "info");
                             $('#tt').datagrid('reload');

                         }
                         else if ((result.indexOf("F") == 0)) {
                             $.messager.alert("提示", "添加失败，请重新操作！", "info");
                             return;
                         }
                         else if ((result.indexOf("L") == 0)) {
                             $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                             top.location = '/index.aspx';
                             return;
                         }
                     }
                 });
             }
         }
      
         function removeUser() {
             var test = document.getElementById("test").value = "delete";
             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要删除的行！", "info");
             }
             if (row) {
                 $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                     if (r) {
                         $('#aspnetForm').form('submit', {
                             url: 'GetTeam.ashx?tid=' + row.tid + "&action=" + test,
                             onSubmit: function () {
                                 //return $(this).form('validate');  
                             },
                             success: function (result) {
                                 if (result.indexOf("T") == 0) {
                                     $('#dlg').dialog('close');
                                     $('#tt').datagrid('clearSelections'); //清空选中的行  
                                     $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                     $('#tt').datagrid('reload');                                  

                                 }
                                 else if ((result.indexOf("F") == 0)) {
                                     $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                     return;
                                 }
                                 else if ((result.indexOf("L") == 0)) {
                                     $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                     top.location = '/index.aspx';
                                     return;
                                 }
                             }
                         });
                     }
                 })
             }
         }         

    </script>
    <style>
        .fitem {
            width:240px;
            float:left;
        }
            .fitem label {
                width:60px;
            }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">


                    <a href="#" onclick="newUser();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-add">添加</a>
                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                </td>
                <td style="text-align: right; padding-right: 15px">
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            名 称
                        </div>
                        <div name="username">
                            编 号
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 550px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">       
        
        <form id="fm" method="post" enctype="multipart/form-data" runat="server">
            <div>

            
            <div class="fitem">
                <label>编号：</label>
                <input id="tbh" name="tbh" class="easyui-validatebox" data-options="validType:'length[1,8]'" />
                <input name="Test" id="test" type="hidden" />
                <input name="tid" id="tid" type="hidden" />     
            </div>

            <div class="fitem">
                <label>姓名：</label>
                <input id="tname" name="tname" class="easyui-validatebox" data-options="required:true,validType:'length[1,8]'" />
            </div>
            <div class="fitem">
                <label>性别：</label> <input id="rsexman"  name="rsexman" type="radio" value="男" checked="checked" />男<input id="rsexwoman" name="rsexwoman" type="radio" value="女" /> 女</div>          
            <div class="fitem" >
                <label>身份证号：</label>
                 <input id="tno" name="tno" class="easyui-validatebox" data-options="validType:'idCard'" />             
            </div>
            <div class="fitem" >
                <label>手机：</label>
                 <input id="tphone" name="tphone" class="easyui-validatebox" data-options="validType:'mobile'" />                 
            </div>
            <div class="fitem" >
                <label>邮箱：</label>
                 <input id="temail" name="temail" class="easyui-validatebox" data-options="validType:'email'"/>                
            </div>
            <div class="fitem" >
                <label>职务：</label>
                 <input id="tpost" name="tpost" class="easyui-validatebox" />               
            </div>
            <div class="fitem" >
                <label>负责区域：</label>
                 <input id="tarea" name="tarea" class="easyui-validatebox" />               
            </div>
            <div class="fitem" >
                <label>职称：</label>
                 <input id="tjob" name="tjob" class="easyui-validatebox" />                 
            </div>
            <div class="fitem" >
                <label>学历：</label>
                 <input id="tedu" name="tedu" class="easyui-validatebox" />                 
            </div>
            <div class="fitem" >
                <label>入职时间：</label>
                 <input id="ttime" name="ttime" class="easyui-datebox" data-options="parser:w4" />                 
            </div>
            <div class="fitem"  style="height:auto;">
                <label>荣誉：</label>
                 <textarea id="thonour" name="thonour" style="width: 150px;" rows="5"></textarea>                
            </div>
                 
            <div class="fitem" style="width:450px;" >
                <label>照片：</label>
                <input id="tpic" name="tpic" type="file" onchange="javascript:setImagePreview(this,localImag,preview);" />
             <input name="htpic" id="htpic" type="hidden" /> 
 
                
                </div>
                <div id="localImag" class="fitem" style="height:100px">  
   <label> 预　　览: </label> 
    <img id="preview" alt="预览图片" onclick="over(preview,divImage,imgbig);" src="../teampics/user.jpg" style="width: 100px; height: 80px;"/>   
</div> 
                <div style="clear:both;"></div>
            </div>          
           
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>  
     
</asp:Content>